home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / misc / sdf / ncdf_rdwr.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  72 lines

  1. ;
  2. ;    Simple example #1
  3. ;
  4. ;    Save a matrix
  5. ;
  6. PRO MakeNetCDFData, filename
  7.  
  8.     ;    Check for a filename. Provide a default if none
  9.     ;    is given.
  10.     IF N_ELEMENTS(filename) EQ 0 THEN filename="ncdf_example.cdf"
  11.  
  12.     ;    Create the NetCDF file
  13.     Id    = NCDF_CREATE(filename,/CLOBBER)
  14.  
  15.     ;    Create dimensions
  16.     Dim1    = NCDF_DIMDEF(Id,'Width',100)
  17.     Dim2    = NCDF_DIMDEF(Id,'Height',200)
  18.  
  19.     ;    Create a variable to hold the data
  20.     VarId    = NCDF_VARDEF(Id,'MyData', [Dim1, Dim2], /FLOAT)
  21.  
  22.     ;    Create some attributes (to tell about our variable)
  23.  
  24.     NCDF_ATTPUT, Id, VarId, "TITLE", "X-Ray of my brain"
  25.     NCDF_ATTPUT, Id, VarId, "UNITS", "Furlongs per Fortnight"
  26.  
  27.     ;    Leave definition mode and enter data write mode
  28.     NCDF_CONTROL, Id, /ENDEF
  29.  
  30.     ;    Create data to store
  31.     Data    = DIST(100,200)
  32.  
  33.     ;    Write the data
  34.     NCDF_VARPUT, Id, VarId, Data
  35.  
  36.     ;    Done
  37.     NCDF_CLOSE, Id
  38. END
  39.  
  40. PRO ReadNetCDFData, filename
  41.  
  42.     ;    Open the file for reading
  43.     Id    = NCDF_OPEN(filename)
  44.  
  45.     ;    Read in the Title. Note that we assume that
  46.     ;    the variable will have an attribute named TITLE.
  47.     ;    This may not be the case in general but for
  48.     ;    our example, we assume it will be there
  49.  
  50.     NCDF_ATTGET, Id, 0, "TITLE", Title
  51.  
  52.     ;    Read the data
  53.     NCDF_VARGET, Id, 'MyData', Data
  54.  
  55.     ;    Now show our data with a title
  56.  
  57.     Print,'Displaying Data'
  58.     erase
  59.     loadct,0
  60.     TVSCL, Data
  61.     XYOUTS, !d.x_size/2, !d.y_size - 20, ALIGNMENT=0.5, /DEVICE, $
  62.         STRING(title)
  63.     NCDF_CLOSE, Id
  64. END
  65.  
  66. PRO ncdf_rdwr,Filename
  67.  
  68.     Print, 'Writing Data' & MakeNetCDFData,filename
  69.     Print, 'Reading Data' & ReadNetCDFData,filename
  70. END
  71.  
  72.